package falling
{
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	import org.flixel.FlxPoint;
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class FallingState1 extends GameState
	{
		[Embed (source = "../../data/falling/1_bg.png")] private var img_bg:Class;
		[Embed (source = "../../data/falling/1_player.png")] private var img_player:Class;
		[Embed (source = "../../data/falling/1_cliff_left.png")] private var img_cliff_left:Class;
		[Embed (source = "../../data/falling/1_cliff_right.png")] private var img_cliff_right:Class;
		[Embed (source = "../../data/falling/1_girl.png")] private var img_girl:Class;
		
		public var bg:FlxSprite;
		public var cliffLeft:FlxSprite;
		public var cliffRight:FlxSprite;
		public var girl:Girl;
		public var player:FlxSprite;
		public var text2:BlurText;
		public var text3:BlurText;
		public var text4:BlurText;
		
		public function FallingState1() 
		{
			
		}
		
		override public function create():void 
		{
			super.create();
			hazy.colorBase = 0xffbbbbbb;
			
			bg = new FlxSprite(0, 0, img_bg);
			hazy.add(bg);
			
			cliffLeft = new FlxSprite( -20, 140, img_cliff_left);
			cliffRight = new FlxSprite( 440, 150, img_cliff_right);
			
			hazy.add(new Bystander(30, 60, cliffLeft));
			hazy.add(new Bystander(95, 95, cliffLeft));
			hazy.add(new Bystander(190, 75, cliffLeft));
			
			hazy.add(new Bystander(500, 95, cliffRight));
			hazy.add(new Bystander(550, 85, cliffRight));
			
			girl = new Girl(470, 105, cliffRight);
			girl.alpha = 0;
			hazy.add(girl);
			
			hazy.add(cliffLeft);
			hazy.add(cliffRight);			
			
			player = new FlxSprite(150, 100, img_player);
			player.velocity.y = 2;
			hazy.add(player);		
			
			var text1:BlurText = new BlurText(20, 10, 28);
			text1.setText("I have this one dream over and over.");
			text1.clearWords = 999;
			text1.clearingToWord = 999;
			above.add(text1);
			
			text2 = new BlurText(20, 50, 18);
			text2.setText("It's not fear that I experience, it's something else.");
			text2.clearWords = 0;
			text2.clearingToWord = 0;
			above.add(text2);
			
			text3 = new BlurText(250, 100, 18);
			text3.setText("It's the ghost of gravity.");
			text3.clearWords = 0;
			text3.clearingToWord = 0;
			above.add(text3);
			
			text4 = new BlurText(300, 145, 15);
			text4.setText("Inevitably, she appears.");
			text4.clearWords = 0;
			text4.clearingToWord = 0;
			above.add(text4);			
		}
		
		override public function update():void 
		{
			super.update();
			
			if (time > 12)
			{
				text2.clearingToWord = 99;
			}
			
			if (time > 19)
			{
				text3.clearingToWord = 99;
			}
			
			if (time > 22)
			{
				cliffLeft.velocity.x = -2;
				cliffLeft.velocity.y = -3;
				cliffRight.velocity.x = 2;
				cliffRight.velocity.y = -3;
				if (player.velocity.y != 4)
				{
					hazy.unblurMask.colorTransform(new Rectangle(0, 0, FlxG.width, FlxG.height), new ColorTransform(0.5, 0.5, 0.5, 1, 0, 0, 0, 0));
					hazy.colorBase = 0xff555555;
				}
				player.velocity.y = 4;
			}
			
			if (time > 45.0)
			{
				FlxG.fade(0xff000000, 0.25, function():void { FlxG.switchState(new FallingState2()); } );
			}
		}
		
	}

}